﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Xdocument = Xceed.Document.NET;
using Xwords = Xceed.Words.NET;

namespace FindSameParagraph
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {

        public ObservableCollection<FilesWithSameParagraph> MyObservableCollection { get; set; }

        ObservableCollection<TxtWithLines> observableCollection = new ObservableCollection<TxtWithLines>();




        public MainWindow()
        {
            InitializeComponent();

            MyObservableCollection = new ObservableCollection<FilesWithSameParagraph>();

            DataContext = this;

        }

        private void SelectFolderButton_Click(object sender, RoutedEventArgs e)
        {
            listbox1.Items.Clear();


            System.Windows.Forms.FolderBrowserDialog folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();

            string path = string.Empty;

            if (folderBrowserDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;

            }
            else
            {
                textBox1.Text = folderBrowserDialog.SelectedPath;

                path = folderBrowserDialog.SelectedPath;

            }

            #region 控制文件类型

            string p = "*";

            List<string> nameListInCurPath = new List<string>();

            nameListInCurPath = Tools.GetFiles(path, p, checkBox1.IsChecked);

            switch (comBox1.SelectedIndex)
            {
                //case 8:
                //    nameListInCurPath = nameListInCurPath.Where(x => x.EndsWith(".txt")).ToList<string>();
                //    break;
                case 0:

                    if (nameListInCurPath.Any(x => x.EndsWith(".doc")))
                    {
                        MessageBoxResult dialogResult = MessageBox.Show("程序无法解析.doc文件，请确认继续执行，还是转换格式后再次运行！", "所选的目录中包含后缀为.doc的文件", MessageBoxButton.YesNo);

                        if (dialogResult != MessageBoxResult.Yes)
                        {
                            return;
                        }
                        else
                        {

                        }

                    }
                    nameListInCurPath = nameListInCurPath.Where(x => x.EndsWith(".docx")).ToList<string>();

                    break;
                //case 2:
                //    nameListInCurPath = nameListInCurPath.Where(x => x.EndsWith(".xls") || x.EndsWith(".pdf")).ToList<string>();
                //    break;
                //case 3:
                //    nameListInCurPath = nameListInCurPath.Where(x => x.EndsWith(".txt") || x.EndsWith(".docx")).ToList<string>();
                //    break;
                //case 4:
                //    nameListInCurPath = nameListInCurPath.Where(x => x.EndsWith(".doc") || x.EndsWith(".docx")).ToList<string>();
                //    break;
                //case 5:
                //    nameListInCurPath = nameListInCurPath.Where(x => x.EndsWith(".pdf")).ToList<string>();
                //    break;
                //case 6:
                //    nameListInCurPath = nameListInCurPath.Where(x => x.EndsWith(".rar") || x.EndsWith(".zip") || x.EndsWith(".7z")).ToList<string>();
                //    break;
                //case 7:
                //    nameListInCurPath = nameListInCurPath.Where(x => x.EndsWith(".doc") || x.EndsWith(".docx") || x.EndsWith(".dwg") || x.EndsWith(".ppt") ||
                //     x.EndsWith(".pptx") || x.EndsWith(".xls") || x.EndsWith(".xlsx") || x.EndsWith("*.pdf")).ToList<string>();
                //    break;
                //case 8:
                //    nameListInCurPath = nameListInCurPath.Where(x => x.EndsWith(".jpg") || x.EndsWith(".JPG") || x.EndsWith(".BMP") || x.EndsWith(".bmp") || x.EndsWith(".png") || x.EndsWith(".PNG") ||
                //    x.EndsWith(".jpeg") || x.EndsWith(".JPEG")).ToList<string>();
                //    break;
                //case 9:
                //    nameListInCurPath = nameListInCurPath.Where(x => x.EndsWith(".bak")).ToList<string>();
                //    break;
                //case 10:
                //    //nameListInCurPath = nameListInCurPath.Where(x => x.EndsWith(textBox2.Text.Trim())).ToList<string>();

                //    string[] tagsTmp = textBox2.Text.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                //    if (tagsTmp.Length > 0)
                //    {
                //        nameListInCurPath = nameListInCurPath.Where(x => tagsTmp.Any(tag => x.EndsWith(tag))).ToList<string>();
                //    }
                //    break;

                default:
                    break;
            }

            #endregion

            if (nameListInCurPath.Count >= 1)
            {
                listbox1.Items.Clear();

            }

            foreach (string item in nameListInCurPath)
            {
                listbox1.Items.Add(item);
            }



        }


        private void ComBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }
        private void Listbox1_Drop(object sender, DragEventArgs e)
        {
            // 检查是否有文件被拖入
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                // 获取拖入的文件路径数组
                string[] files = e.Data.GetData(DataFormats.FileDrop) as string[];

                if (files != null)
                {
                    // 遍历文件路径并添加到ListBox的Items中
                    foreach (string filePath in files)
                    {
                        if (listbox1.Items.Contains(filePath))
                        {
                            continue;
                        }
                        switch (comBox1.SelectedIndex)
                        {
                            case 5:
                                if (filePath.EndsWith(".txt"))
                                {
                                    listbox1.Items.Add(filePath);
                                }
                                break;
                            case 0:
                                if (filePath.EndsWith(".docx"))
                                {
                                    listbox1.Items.Add(filePath);
                                }
                                break;
                            case 2:
                                if (filePath.EndsWith(".pdf"))
                                {
                                    listbox1.Items.Add(filePath);
                                }
                                break;

                            case 3:
                                if (filePath.EndsWith(".docx"))
                                {
                                    listbox1.Items.Add(filePath);
                                }
                                if (filePath.EndsWith(".txt"))
                                {
                                    listbox1.Items.Add(filePath);
                                }
                                break;

                            default:
                                break;
                        }

                    }
                }
            }


        }


        public bool? ChkChecked { get; set; }


        private void Button_Click(object sender, RoutedEventArgs e)
        {
            /*

            bool toSimplity = false;

            if (comboBox2.SelectedIndex==1)
            {
                toSimplity = true;
            }


            int strCount = 6;

            bool b = int.TryParse(textBox1_Copy.Text, out strCount);
            
            List<string> listStr = new List<string>();
            
            List<List<string>> allParas = new List<List<string>>();

            for (int i = 0; i < listbox1.Items.Count; i++)
            {
                List<string> paras = new List<string>();

                string filePath = listbox1.Items[i].ToString();

                using (var doc = Xwords.DocX.Load(filePath))
                {

                    //遍历文档中的所有段落
                    foreach (Xdocument.Paragraph paragraph in doc.Paragraphs)
                    {

                        //MessageBox.Show(paragraph.ParentContainer.ToString());

                        //只处理在正文中的重复内容

                        if (paragraph.ParentContainer != Xdocument.ContainerType.Cell)
                        {
                            string line = paragraph.Text;

                            line = Regex.Replace(line, @"\s", "");

                            if (toSimplity)
                            {
                                line = Regex.Replace(line, @"[^\u4e00-\u9fa5a-zA-Z0-9\.]", "");
                            }
                            
                            if (line.Trim().Length >= strCount)
                            {
                                paras.Add(line);
                            }

                        }

                    }

                }

                allParas.Add(paras);

            }
            
            Dictionary<(int, int), List<string>> keyValuePairs = FindCommonStringsD(allParas);
      
            MessageBox.Show(keyValuePairs.Count.ToString());

            foreach (var pair in keyValuePairs)
            {
                // Create a new table with 3 rows and 2 columns
                Table table = new Table();
                
                //table.Background = Brushes.LightBlue;

                table.Columns.Add(new TableColumn());
                table.Columns.Add(new TableColumn());

                table.Columns[0].Width = new GridLength(1, GridUnitType.Star);

                table.Columns[1].Width = new GridLength(2, GridUnitType.Star);

                // Add rows to the table
                TableRowGroup rowGroup = new TableRowGroup();
                table.RowGroups.Add(rowGroup);

                //MessageBox.Show(table.RowGroups.Count.ToString());

                int index = 0;
                int j = 0;

                foreach (var str in pair.Value)
                {

                    TableRow row1 = new TableRow();
                    
                    rowGroup.Rows.Add(row1);
                    
                    string fileNameFir = listbox1.Items[pair.Key.Item1].ToString();

                    string fileNameSec = listbox1.Items[pair.Key.Item2].ToString();

                    string fileNameAll = fileNameFir + "\r\n" + "与" + "\r\n" + fileNameSec + "\r\n" + "相同的内容包括：";

                    Run runTitle = new Run(fileNameAll);

                    //runTitle.FontSize = flowDocument.FontSize * 1.5;

                    runTitle.Foreground = Brushes.Red;

                    if (index!=0)
                    {
                        fileNameAll = string.Empty;
                    }
                    TableCell tableCellColumnA = new TableCell(new Paragraph(runTitle));

                    tableCellColumnA.BorderBrush = Brushes.Black;

                    tableCellColumnA.BorderThickness = new Thickness(0.5);
                    

                    TableCell tableCellColumnB = new TableCell(new Paragraph(new Run(str)));

                    tableCellColumnB.BorderBrush = Brushes.Black;

                    tableCellColumnA.BorderThickness = new Thickness(0.5);
                    tableCellColumnB.BorderThickness = new Thickness(0.5);


                    row1.Cells.Add(tableCellColumnA);
                
                    row1.Cells.Add(tableCellColumnB);

                    j++;
                    
                }
                
                int startCol = 0;

                int startRow = 0;

                int rowSpan = rowGroup.Rows.Count;

                int colSpan = 1;

                TableCell startCell = rowGroup.Rows[startRow].Cells[startCol];

                var contentType = startCell.Blocks.FirstBlock;

                // 设置 RowSpan 和 ColumnSpan
                startCell.RowSpan = rowSpan;

                startCell.ColumnSpan = colSpan;

                startCell.TextAlignment = TextAlignment.Left;


                // 删除被合并的单元格
                for (int row = startRow; row < startRow + rowSpan; row++)
                {
                    for (int col = startCol; col < startCol + colSpan; col++)
                    {
                        if (row == startRow && col == startCol) continue; // 跳过起始单元格

                        rowGroup.Rows[row].Cells.RemoveAt(col);
                    }
                }
                //处理表格边框

                //SetTableBorder(table);

                flowDocument.Blocks.Add(table);
                
            }

            int backgroundColorIndex = 0;
            foreach (var item in flowDocument.Blocks)
            {
                if (backgroundColorIndex % 2 == 0)
                {
                    item.Background = Brushes.AliceBlue;
                }
                else
                {
                    item.Background = Brushes.White;
                }


                backgroundColorIndex += 1;

            }



    */
        }


        private static void SetTableBorder(Table table)
        {

            int groupCount = table.RowGroups.Count;

            int columnCount = table.Columns.Count;


            if (groupCount == 0)
            {
                return;
            }
            //只有一组的情况
            else if (groupCount == 1)
            {
                int rowCount = table.RowGroups[0].Rows.Count;

                //只有一组，只有一行的情况 ok
                if (rowCount == 1)
                {

                    for (int j = 0; j < columnCount; j++)
                    {
                        TableCell tableCell = table.RowGroups[0].Rows[0].Cells[j];

                        if (j == 0)
                        {
                            tableCell.BorderBrush = Brushes.Red;

                            tableCell.BorderThickness = new Thickness(2, 2, 1, 2);

                        }
                        else if (j == columnCount - 1)
                        {
                            tableCell.BorderBrush = Brushes.Red;

                            tableCell.BorderThickness = new Thickness(0, 2, 2, 2);
                        }
                        else
                        {
                            tableCell.BorderBrush = Brushes.Blue;

                            tableCell.BorderThickness = new Thickness(0, 2, 1, 2);
                        }

                    }

                }
                //只有一组，但是多行的情况
                else if (rowCount > 1)
                {
                    for (int i = 0; i < rowCount; i++)
                    {
                        //第一行
                        if (i == 0)
                        {
                            for (int j = 0; j < columnCount; j++)
                            {
                                TableCell tableCell = table.RowGroups[0].Rows[i].Cells[j];

                                if (j == 0)
                                {
                                    tableCell.BorderBrush = Brushes.Red;

                                    tableCell.BorderThickness = new Thickness(2, 2, 1, 1);

                                }
                                else if (j == columnCount - 1)
                                {
                                    tableCell.BorderBrush = Brushes.Red;

                                    tableCell.BorderThickness = new Thickness(0, 2, 2, 1);

                                }
                                else
                                {
                                    tableCell.BorderBrush = Brushes.Red;

                                    tableCell.BorderThickness = new Thickness(0, 2, 1, 1);

                                }








                            }

                        }
                        //最后行情况
                        else if (i == rowCount - 1)
                        {
                            for (int j = 0; j < columnCount; j++)
                            {
                                TableCell tableCell = table.RowGroups[0].Rows[i].Cells[j];

                                if (j == 0)
                                {
                                    tableCell.BorderBrush = Brushes.Red;

                                    tableCell.BorderThickness = new Thickness(2, 0, 1, 2);

                                }
                                else if (j == columnCount - 1)
                                {
                                    tableCell.BorderBrush = Brushes.Red;

                                    tableCell.BorderThickness = new Thickness(0, 0, 1, 2);
                                }
                                else
                                {
                                    tableCell.BorderBrush = Brushes.Blue;

                                    tableCell.BorderThickness = new Thickness(0, 0, 1, 2);
                                }

                            }
                        }
                        //中间行
                        else
                        {

                            for (int j = 0; j < columnCount; j++)
                            {
                                MessageBox.Show(i.ToString());
                                MessageBox.Show(j.ToString());

                                TableCell tableCell = table.RowGroups[0].Rows[i].Cells[j];

                                if (j == 0)
                                {
                                    tableCell.BorderBrush = Brushes.Red;

                                    tableCell.BorderThickness = new Thickness(2, 0, 1, 1);

                                }
                                else if (j == columnCount - 1)
                                {
                                    tableCell.BorderBrush = Brushes.Red;

                                    tableCell.BorderThickness = new Thickness(0, 0, 2, 1);
                                }
                                else
                                {
                                    tableCell.BorderBrush = Brushes.Blue;

                                    tableCell.BorderThickness = new Thickness(0, 0, 1, 1);
                                }

                            }

                        }

                    }

                }
                else
                {
                    return;
                }

            }
            //存在多组的情况
            else
            {
                for (int k = 0; k < groupCount; k++)
                {
                    int rowCount = table.RowGroups[k].Rows.Count;

                    for (int i = 0; i < rowCount; i++)
                    {
                        for (int j = 0; j < columnCount; j++)
                        {
                            TableCell tableCell = table.RowGroups[k].Rows[i].Cells[j];

                            //第一组 顶行
                            if (k == 0 && i == 0)
                            {
                                if (j == 0)
                                {
                                    tableCell.BorderBrush = Brushes.Red;
                                    tableCell.BorderThickness = new Thickness(2, 2, 1, 1);
                                }
                                else if (j == columnCount - 1)
                                {
                                    tableCell.BorderBrush = Brushes.Red;
                                    tableCell.BorderThickness = new Thickness(0, 2, 2, 1);
                                }
                                else
                                {
                                    tableCell.BorderBrush = Brushes.Red;
                                    tableCell.BorderThickness = new Thickness(0, 2, 1, 1);
                                }

                            }
                            else if (k == groupCount - 1 && j == columnCount - 1)
                            {
                                if (j == 0)
                                {
                                    tableCell.BorderBrush = Brushes.Red;
                                    tableCell.BorderThickness = new Thickness(2, 0, 1, 2);
                                }
                                else if (j == columnCount - 1)
                                {
                                    tableCell.BorderBrush = Brushes.Red;
                                    tableCell.BorderThickness = new Thickness(0, 0, 2, 2);
                                }
                                else
                                {
                                    tableCell.BorderBrush = Brushes.Red;
                                    tableCell.BorderThickness = new Thickness(0, 0, 1, 2);
                                }

                            }
                            else
                            {
                                if (j == 0)
                                {
                                    tableCell.BorderBrush = Brushes.Red;
                                    tableCell.BorderThickness = new Thickness(2, 0, 1, 1);
                                }
                                else if (j == columnCount - 1)
                                {
                                    tableCell.BorderBrush = Brushes.Red;
                                    tableCell.BorderThickness = new Thickness(0, 0, 2, 1);
                                }
                                else
                                {
                                    tableCell.BorderBrush = Brushes.Red;
                                    tableCell.BorderThickness = new Thickness(0, 0, 1, 1);
                                }

                            }

                        }
                    }

                }

            }


        }

        static List<string> FindCommonStrings(List<List<string>> allLists)
        {
            if (allLists == null || allLists.Count == 0)
            {
                return new List<string>();
            }

            // 使用第一个列表作为初始集合
            IEnumerable<string> commonStrings = allLists[0];

            // 逐个与其他列表取交集
            foreach (var list in allLists.Skip(1))
            {
                commonStrings = commonStrings.Intersect(list);
            }

            return commonStrings.ToList();
        }

        static Dictionary<(int, int), List<string>> FindCommonStringsD(List<List<string>> allLists)
        {
            var commonStrings = new Dictionary<(int, int), List<string>>();

            // 遍历每一对列表
            for (int i = 0; i < allLists.Count; i++)
            {
                for (int j = i + 1; j < allLists.Count; j++)
                {
                    // 找到两个列表的交集
                    var intersection = allLists[i].Intersect(allLists[j]).ToList();

                    // 如果有交集，记录下来
                    if (intersection.Any())
                    {
                        commonStrings[(i, j)] = intersection;
                    }
                }
            }

            return commonStrings;
        }


        private void DataGrid2_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            e.Row.Header = (e.Row.GetIndex() + 1).ToString();
        }

        private void Listbox1_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {

        }

        private void FindKeyWordButton_Click(object sender, RoutedEventArgs e)
        {

        }

        private void ContainTag_PreviewKeyDown(object sender, KeyEventArgs e)
        {

        }

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            //System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();

            //saveFileDialog.FilterIndex = 0;

            //saveFileDialog.Filter = "Rtf files (*.rtf)|.rtf";

            //if (saveFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            //{
            //    return;
            //}

            //string filePath = saveFileDialog.FileName;

            //using (FileStream fs = new FileStream(filePath, FileMode.Create))
            //{
            //    TextRange textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
            //    textRange.Save(fs, DataFormats.Rtf);
            //}

        }

        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            //直接写入到datagrid 中

            bool toSimplity = false;

            if (comboBox2.SelectedIndex == 1)
            {
                toSimplity = true;
            }


            int strCount = 6;

            bool b = int.TryParse(textBox1_Copy.Text, out strCount);

            List<string> listStr = new List<string>();

            List<List<string>> allParas = new List<List<string>>();

            for (int i = 0; i < listbox1.Items.Count; i++)
            {
                List<string> paras = new List<string>();

                string filePath = listbox1.Items[i].ToString();

                using (var doc = Xwords.DocX.Load(filePath))
                {

                    //遍历文档中的所有段落
                    foreach (Xdocument.Paragraph paragraph in doc.Paragraphs)
                    {

                        //MessageBox.Show(paragraph.ParentContainer.ToString());

                        //只处理在正文中的重复内容

                        if (paragraph.ParentContainer != Xdocument.ContainerType.Cell)
                        {
                            string line = paragraph.Text;

                            line = Regex.Replace(line, @"\s", "");

                            if (toSimplity)
                            {
                                line = Regex.Replace(line, @"[^\u4e00-\u9fa5a-zA-Z0-9\.]", "");
                            }

                            if (line.Trim().Length >= strCount)
                            {
                                paras.Add(line);
                            }

                        }

                    }

                }

                allParas.Add(paras);

            }

            Dictionary<(int, int), List<string>> keyValuePairs = FindCommonStringsD(allParas);

            MessageBox.Show(keyValuePairs.Count.ToString());

            foreach (var pair in keyValuePairs)
            {

                FilesWithSameParagraph filesWithSameParagraph = new FilesWithSameParagraph();

                ObservableCollection<SameParagraphInFile> sameParagraphInFiles = new ObservableCollection<SameParagraphInFile>();

                List<string> tmpStrs = new List<string>();

                string fileNameFir = listbox1.Items[pair.Key.Item1].ToString();

                string fileNameSec = listbox1.Items[pair.Key.Item2].ToString();

                filesWithSameParagraph.FileName = fileNameFir + "\r\n" + "与" + "\r\n" + fileNameSec + "\r\n" + "相同的内容包括：";



                foreach (var str in pair.Value)
                {
                    tmpStrs.Add(str);

                    SameParagraphInFile sameParagraphInFile = new SameParagraphInFile();

                    sameParagraphInFile.SameParagraph = str;
                    
                    sameParagraphInFiles.Add(sameParagraphInFile);

                }


                filesWithSameParagraph.SameParagraph = tmpStrs;

                filesWithSameParagraph.SameParagraphInFiles = sameParagraphInFiles;

                MyObservableCollection.Add(filesWithSameParagraph);

            }



            //datagrid.ItemsSource = myObservableCollection;




        }

        private void Button2_Click(object sender, RoutedEventArgs e)
        {
            MyObservableCollection = new ObservableCollection<FilesWithSameParagraph> {
                new FilesWithSameParagraph{
                    FileName="woshi 试验品 1",
                     SameParagraphInFiles=new ObservableCollection<SameParagraphInFile>
                     {
                         new SameParagraphInFile{ SameParagraph = "段落 1.1" },
                         new SameParagraphInFile{ SameParagraph = "段落 1.2" }
                     }

                },
                new FilesWithSameParagraph{

                         FileName="woshi 试验品 2",
                     SameParagraphInFiles=new ObservableCollection<SameParagraphInFile>
                     {
                         new SameParagraphInFile{ SameParagraph = "段落 2.1" },
                         new SameParagraphInFile{ SameParagraph = "段落 2.2" }
                     }

                }


            };
        }

        private void MenuItem_Click_1(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();

            System.Windows.Forms.DialogResult dialogResult = openFileDialog.ShowDialog();

            string fileName = openFileDialog.FileName;

            if (File.Exists(fileName)&&fileName.EndsWith(".docx"))
            {
                if (listbox1.Items.Contains(fileName)==false)
                {
                    listbox1.Items.Add(fileName);
                }
             
            }
            
        }

        private void MenuItem_Click_2(object sender, RoutedEventArgs e)
        {
            listbox1.Items.Clear();
        }
    }


    public class TxtWithLines
    {
        string name;
        List<string> lineStrs;
        string findStr;
        string allContent;
        List<Color> colors;
        List<string> findStringList = new List<string>();

        public TxtWithLines(string _fileNmae, List<string> _lineStrs)
        {
            Name = _fileNmae;

            LineStrs = _lineStrs;

            string tmpStr = string.Empty;

            foreach (var item in _lineStrs)
            {

                findStringList.Add(item.TrimEnd('\r', '\n'));

                tmpStr = tmpStr + item + "\r\n";

            }

            findStr = tmpStr.TrimEnd('\r', '\n');

            //if (File.Exists(_fileNmae))
            //{
            //    using (StreamReader reader = new StreamReader(_fileNmae))
            //    {
            //        AllContent = reader.ReadToEnd();
            //    }
            //}

        }

        public string Name { get => name; set => name = value; }
        public List<string> LineStrs { get => lineStrs; set => lineStrs = value; }
        public string FindStr { get => findStr; set => findStr = value; }
        public string AllContent { get => allContent; set => allContent = value; }
        public List<Color> Colors { get => colors; set => colors = value; }
        public List<string> FindStringList { get => findStringList; set => findStringList = value; }
    }

    public class FilesWithSameParagraph
    {
        public string FileName { get; set; }

        public ObservableCollection<SameParagraphInFile> SameParagraphInFiles { get; set; }
        
        public List<string> SameParagraph { get; set; }
        
    }

    public class SameParagraphInFile
    {
        public string SameParagraph { get; set; }
        
    }


    public class Tools
    {
        public static List<string> GetFiles(string filepath, string pattern, bool? childFolder)
        {
            string p = pattern;

            List<string> f_name_list = new List<string>();

            f_name_list = System.IO.Directory.GetFiles(filepath, p, System.IO.SearchOption.TopDirectoryOnly).ToList<string>();

            if (childFolder == true)
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(filepath);

                directoryInfo.Refresh();

                foreach (System.IO.DirectoryInfo item in directoryInfo.EnumerateDirectories())
                {

                    try
                    {
                        if ((item.Attributes & FileAttributes.System) == System.IO.FileAttributes.System || (item.Attributes & FileAttributes.Hidden) == System.IO.FileAttributes.Hidden)
                        {

                        }
                        else
                        {
                            //MessageBox.Show(item.FullName + item.Attributes.ToString());

                            foreach (var fileInfo in item.GetFiles("*", System.IO.SearchOption.AllDirectories))
                            {
                                f_name_list.Add(fileInfo.FullName);

                            }

                        }

                    }
                    catch (Exception)
                    {

                        //throw;
                        continue;
                    }

                }

            }

            return f_name_list;
        }
    }





}
